package com.gzck.gzck_verson2.service.impl;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.lang.intern.InternUtil;
import com.gzck.gzck_verson2.mapper.GFwdUserprivilegeMapper;
import com.gzck.gzck_verson2.pojo.GFwdUserprivilege;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 自定义权限加载接口实现类
 */
@Component    // 保证此类被 SpringBoot 扫描，完成 Sa-Token 的自定义权限验证扩展
public class StpInterfaceImpl implements StpInterface {
    @Autowired
    GFwdUserprivilegeServiceImpl gfwdUserprivilegeServiceImpl;
    @Autowired
    GFwdUserinfoServiceImpl gfwdUserinfoServiceImpl;
    @Autowired
    GFwdUserprivilegeMapper gFwdUserprivilegeMapper;

    /**
     * 返回一个账号所拥有的权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        GFwdUserprivilege gFwdUserprivilege = gFwdUserprivilegeMapper.getByUserId(loginId.toString());
        ArrayList<String> privileges = new ArrayList<>();
        switch (gFwdUserprivilege.getPrivilege()) {
            case "1":
                privileges.add("1");
                privileges.add("2");
                privileges.add("3");
                privileges.add("4");
                return privileges;
            case "2":
                privileges.add("1");
            default:
                throw new RuntimeException("没有权限！");
        }
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
//        // 本 list 仅做模拟，实际项目中要根据具体业务逻辑来查询角色
//        List<String> list = new ArrayList<String>();
//        list.add("admin");
//        list.add("super-admin");
        return null;

    }

}
